package com.demo.page.controller.banner;


import com.demo.common.entity.Banner;
import com.demo.common.entity.Meta;
import com.demo.page.feign.banner.BannerFeign;
import com.demo.page.feign.columnManagement.ColumnManagementFeign;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 头部、中间轮播图
 * 作者：孙佳佳
 * 改bug：张佑威
 * 分配任务：张改
 * 插入数据：孙佳佳、张佑威
 * 接口文档：贾冠博
 */
@RestController
@CrossOrigin
public class BannerController {
    @Resource
    private BannerFeign bannerFeign;
    @Resource
    private ColumnManagementFeign columnManagementFeign;

    /**
     * 头部图片
     * @return
     */
    @GetMapping("/Banner/getAllOne")
    public Map getAllOne() {
        System.out.println(9100);
        List<Banner> banners = bannerFeign.getAllOne();
        Map<String, Object> dates = new HashMap<>();
        Map<String, Object> meta = new HashMap<>();
        dates.put("banners", banners);
        meta.put("date", dates);
        if(banners.size()>0){
            meta.put("meta", new Meta("获取成功", "200"));
        }else {
            meta.put("meta", new Meta("获取失败", "404"));
        }

        return meta;
    }
    /**
     * 解决方案图片
     * @param query
     * @return
     */
    @GetMapping("/Banner/getAllTwo")
    public Map fallAll(@RequestParam(name = "query",required = false,defaultValue = "解决方案") String query) {
        List<Banner> banners = bannerFeign.getAllTwo();
        Map<String, Object> dates = new HashMap<>();
        Map<String, Object> meta = new HashMap<>();
        dates.put("banners", banners);
        meta.put("date", dates);
        if(banners.size()>0){
                                                                                                                                                          meta.put("meta", new Meta("获取成功", "200"));
        }else {
            meta.put("meta", new Meta("获取失败", "404"));
        }

        return meta;
    }


    //    查询所有新闻图片
    @GetMapping("/Banner/ ")
    public List<Banner> newsAll(){
        return bannerFeign.newsAll();
    }
}
